﻿using System;
using LevelEditor.Document;
using LevelEditor.Forms;

namespace LevelEditor.View
{
    public class DoUndoTileSetOptions : DoUndoNothing
    {
        #region Fields

        int LayerIndex;

        int Index;

        TileSet DoTileSet;

        TileSet UndoTileSet;

        #endregion

        #region Constructors

        public DoUndoTileSetOptions(MainForm form, int index, TileSet tileSet):base(form)
        {
            if (tileSet == null)
                throw new NullReferenceException();
            LayerIndex = form.CurrentLayer;
            Index = index;
            DoTileSet = tileSet;
            UndoTileSet = form.Level.Layers[LayerIndex].TileSets[Index];
        }

        #endregion

        #region Methods

        public override bool Do()
        {
            MainForm.Level.Layers[LayerIndex].TileSets[Index] = new TileSet(DoTileSet);
            MainForm.CurrentLayer = LayerIndex;
            MainForm.RefreshControlData();
            MainForm.Palette.tabs.SelectedIndex = Index;
            MainForm.Palette.ResetBitmap(MainForm, Index);
            return base.Do();
        }

        public override void Undo()
        {
            MainForm.Level.Layers[LayerIndex].TileSets[Index] = new TileSet(UndoTileSet);
            MainForm.CurrentLayer = LayerIndex;
            MainForm.RefreshControlData();
            MainForm.Palette.tabs.SelectedIndex = Index;
            MainForm.Palette.ResetBitmap(MainForm, Index);

        }

        public override string ToString()
        {
            return "Tile set " + Index.ToString() + " options";
        }

        #endregion
    }
}
